class Studentmanager(object):
        def __init__(self):
             self.student_list = []
            
        def run(self):
                # self.load_student()
            self.lode_student()
            while True:
                self.show_menu()
                menu_num = int(input('请输入您需要执行的功能序号'))

                if menu_num == 1: #添加学员
                    self.add_student()
                elif menu_num == 2: #删除学员
                    self.del_student()
                elif menu_num == 3:  #修改学员
                    self.change_student()
                elif menu_num == 4:  #查询
                    self.query_student()
                elif menu_num == 5:  #显示所有
                    self.show_all_student()
                elif menu_num == 6:  #保存学员
                    self.save_student()
                elif menu_num == 7:  #退出
                    break
        @staticmethod
        def show_menu():
            print('请选择下列功能')
            print('1:添加')
            print('2:删除')
            print('3:修改')
            print('4:查询')
            print('5:显示所有')
            print('6:保存学员')
            print('7：退出系统')
        def add_student(self):
            name = input('请输入您的姓名')
            gender = input('请输入学员性别')
            tel = input('请输入学员的联系方式')

            student =  Student(name,gender,tel)
            self.student_list.append(student)
            print(self.student_list)
            print(student)

        def del_student(self):
           del_name = input('请输入您想要删除的学员')
           for i  in self.student_list:
                if del_name == i.name:
                    self.student_list.remove(i)
                    break
                else:
                    print('查不到该学员信息')

        print(self.student_list)

        def change_student(self):
            change_name = input('请输入您想要修改的学员信息')
            for i in self.student_list:
                if i.name == change_name:
                    i.name = input('请输入您要修改的学员姓名')
                    i.gender = input('请输入您要修改的学员性别')
                    i.tel = input('请输入您要修改的学员联系方式')
                    print(f'修改学员信息内容为，姓名{i.name},性别{i.gender},联系方式{i.tel}')
                    break
                else:
                    print('查不到该学员的信息')
        def query_student(self):
            query_name = input('请输入您要查找的学员信息')
            for i in self.student_list:
                    if  i.name == query_name:
                        print(f'姓名{i.name},性别{i.gender},联系方式{i.tel}')
                        break
                    else:
                        print('找不到该学员信息')
    
        def show_all_student(self):
            print('姓名\t性别\t手机号')
            for i in self.student_list:
                print(f'{i.name}\t{i.gender}\t{i.tel}')

        def save_student(self):
            f = open('student.data','w')
            new_list = [i.__dict__ for i in self.student_list]
            print(new_list)
            f.write(str(new_list))
            f.close()
        def lode_student(self):
            try:
                f = open('student.data','r')
            except:
                f = open('student.data','w')
            else:
                data = f.read()
                new_list = eval(data)
                self.student_list =  [Student(i['name'],i['gender'],i['tel']) for i in new_list]
            finally:
                f.close()
